<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>CMS - 派后台管理系统</title>
    <link rel="icon" href="__ADMIN_PATH__favicon.ico" type="image/ico">
    <meta name="keywords" content="派后台管理系统">
    <meta name="description" content="派后台管理系统">
    <meta name="author" content="cfn">
    <link href="__ADMIN_PATH__css/bootstrap.min.css" rel="stylesheet">
    <link href="__ADMIN_PATH__css/materialdesignicons.min.css" rel="stylesheet">
    <link href="__ADMIN_PATH__css/style.min.css" rel="stylesheet">
    <!--select2-->
    <link href="__ADMIN_PATH__css/select2.min.css" rel="stylesheet">
    <!--弹出框-->
    <link rel="stylesheet" href="__ADMIN_PATH__js/jconfirm/jquery-confirm.min.css">
    <!--时间选择插件-->
    <link rel="stylesheet" href="__ADMIN_PATH__js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">
    <style>

    </style>
</head>
<body>
<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    <form action="#!" method="post" class="row" id="myForm">
                        <div class="form-group col-md-12">
                            <label for="name">文章名称</label>
                            <input type="text" class="form-control" id="name" name="name" value="" placeholder="文章名称" />
                        </div>
                        <div class="form-group col-md-12">
                            <label for="cid">栏目分类</label>
                            <div class="form-controls">
                                <select name="cid" class="form-control" id="cid">
                                    <option value="0">请选择</option>
                                    {volist name="category" id="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="author">作者</label>
                            <input type="text" class="form-control" id="author" name="author" value="" placeholder="作者" />
                        </div>
                        <div class="form-group col-md-12">
                            <label for="image">主图</label>
                            <div class="input-group">
                                <input type="text" class="form-control" name="image" id="image" value="" />
                                <input type="file" id="fileimage" style="display: none;" onchange="upload('image')"/>
                                <div class="input-group-btn"><button class="btn btn-default" type="button" onclick="btnClick('image')">上传</button></div>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="is_recommend">推荐</label>
                            <div class="clearfix">
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="is_recommend" value="1"><span>是</span>
                                </label>
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="is_recommend" value="0" checked><span>否</span>
                                </label>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="is_hot">热门</label>
                            <div class="clearfix">
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="is_hot" value="1"><span>是</span>
                                </label>
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="is_hot" value="0" checked><span>否</span>
                                </label>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="is_top">顶置</label>
                            <div class="clearfix">
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="is_top" value="1"><span>是</span>
                                </label>
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="is_top" value="0" checked><span>否</span>
                                </label>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="abstract">摘要</label>
                            <textarea name="abstract" id="abstract" class="form-control"></textarea>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="content">文章内容</label>
                            <textarea id="content" name="content"></textarea>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="tag">文章标签</label>
                            <div class="form-controls">
                                <select name="tag" class="form-control" id="tag" multiple="multiple">
                                    {volist name="tag" id="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label for="show_time">发布时间</label>
                            <input class="form-control js-datetimepicker" type="text" id="show_time" name="show_time" placeholder="请选择具体时间" value="" data-side-by-side="true" data-locale="zh-cn" data-format="YYYY-MM-DD HH:mm:ss" />
                        </div>
                        <div class="form-group col-md-12">
                            <label for="status">状态</label>
                            <div class="clearfix">
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="status" value="1" checked><span>启用</span>
                                </label>
                                <label class="lyear-radio radio-inline radio-primary">
                                    <input type="radio" name="status" value="0"><span>禁用</span>
                                </label>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <button type="submit" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__ADMIN_PATH__js/jquery.min.js"></script>
<script type="text/javascript" src="__ADMIN_PATH__js/bootstrap.min.js"></script>
<script type="text/javascript" src="__ADMIN_PATH__js/main.min.js"></script>
<!--弹出框-->
<script src="__ADMIN_PATH__js/jconfirm/jquery-confirm.min.js"></script>
<!--弹出框架-->
<script type="text/javascript" src="__ADMIN_PATH__js/iframe.js"></script>
<!--时间选择插件-->
<script src="__ADMIN_PATH__js/bootstrap-datetimepicker/moment.min.js"></script>
<script src="__ADMIN_PATH__js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="__ADMIN_PATH__js/bootstrap-datetimepicker/locale/zh-cn.js"></script>
<!--富文本输入框-->
<script src="__ADMIN_PATH__js/tinymce/tinymce.min.js"></script>
<!--通知-->
<script src="__ADMIN_PATH__js/bootstrap-notify.min.js"></script>
<!--select2-->
<script src="__ADMIN_PATH__js/select2.min.js"></script>
<script type="text/javascript" src="__ADMIN_PATH__js/lightyear.js"></script>
<script>
    $(function () {
        $('#tag').select2();
    });
    $(document).ready(function(){
        tinymce.init({
            selector: '#content',
            language: 'zh_CN',
            directionality: 'ltl',
            browser_spellcheck: true,
            contextmenu: false,
            height: 480,
            plugins: [
                "advlist autolink lists link image charmap print preview anchor",
                "searchreplace visualblocks code fullscreen",
                "insertdatetime media table contextmenu paste imagetools wordcount",
                "code"
            ],
            toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
            images_upload_url: '/admin/widget.files/tinymce',
        });
    });
    /**
     * 选择文件
     * @param inputName
     */
    function btnClick(inputName) {
        $("#file"+inputName).click()
    }
    /**
     * 异步上传
     * @param inputName
     */
    function upload(inputName) {
        var formData = new FormData();
        formData.append("file",$("#file"+inputName)[0].files[0]);
        $.ajax({
            type:'POST',
            url:'/admin/widget.files/image',
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            success: function (res) {
                if (!Array.isArray(res)) res = jQuery.parseJSON(res);
                $("#"+inputName).val(res.data.filePath);
            }
        });
    }
    $("#myForm").submit(function () {
        $cid = $('#cid option:selected').val();
        $content = tinymce.get('content').getContent();
        $show_time = $('#show_time').val();
        $name = $('#name').val();
        $abstract = $('#abstract').val();
        $author = $('#author').val();
        $image = $('#image').val();
        $is_recommend = $('input[name=is_recommend]:radio:checked').val();
        $is_hot = $('input[name=is_hot]:radio:checked').val();
        $is_top = $('input[name=is_top]:radio:checked').val();
        var $tag = "";
        $('#tag option:selected').each(function() {
            $tag += $(this).attr("value")+",";
        });
        $show_time = $('#show_time').val();
        $status = $('input[name=status]:radio:checked').val();
        if ($cid == 0) {lightyear.notify("栏目分类不能为空", 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');return false;}
        if ($name == '') {lightyear.notify("文章名称不能为空", 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');return false;}
        if ($author == '') {lightyear.notify("作者不能为空", 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');return false;}
        $.post(url="/admin/cms.cms_article/save",data={
            "cid":$cid,
            "content":$content,
            "show_time":$show_time,
            "status":$status,
            "is_recommend":$is_recommend,
            "is_hot":$is_hot,
            "is_top":$is_top,
            "name":$name,
            "image":$image,
            "tag":$tag,
            "author":$author,
            "abstract":$abstract,
        },function (res) {
            if (res.code == 200) {lightyear.notify(res.msg, 'success', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');setTimeout(function () {parent.location.reload()},2000)}
            else lightyear.notify(res.msg, 'danger', 3000, 'mdi mdi-emoticon-happy', 'top', 'center');
        });
        return false;
    })
</script>
</body>
</html>